//
//  MessageTableViewCell.swift
//  ezyform
//
//  Created by Hubert on 2022/5/9.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit

class MessageTableViewCell: UITableViewCell {
    let titleL = ContentLabel(R.font.interMedium(size: 15))
    let contentL = ContentLabel(hexStr: "#292D3299")
    let timeL = ContentLabel(R.font.interRegular(size: 13),hexStr: "#292D3299")
    let redV: UIView = UIView()
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpviews()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    func setUpviews(){
        self.selectionStyle = .none
        self.backgroundColor = .white
        //red circle
        redV.backgroundColor = UIColor.init(hexStr: "#ED3E3E")
        redV.layer.cornerRadius = 4
        self.contentView.addSubview(redV)
        redV.snp.makeConstraints { make in
            make.top.equalTo(24)
            make.left.equalTo(16)
            make.height.width.equalTo(8)
        }
        //title
        titleL.numberOfLines = 1
        titleL.textAlignment = .left
        self.contentView.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.left.equalTo(redV.snp.right).offset(6)
            make.top.equalTo(20)
            make.right.equalTo(-16)
            make.height.greaterThanOrEqualTo(0)
        }
        
        //summary
        contentL.numberOfLines = 0
        self.contentView.addSubview(contentL)
        contentL.snp.makeConstraints { make in
            make.top.equalTo(titleL.snp.bottom).offset(8)
            make.left.equalTo(titleL)
            make.right.equalTo(titleL)
            make.height.greaterThanOrEqualTo(0)
        }
        let timeImageView = UIImageView(image: R.image.notification_list_time())
        self.contentView.addSubview(timeImageView)
        timeImageView.snp.makeConstraints { make in
            make.top.equalTo(contentL.snp.bottom).offset(16)
            make.left.equalTo(contentL)
            make.width.height.equalTo(16)
        }
        //time label
        self.contentView.addSubview(timeL)
        timeL.snp.makeConstraints { make in
            make.left.equalTo(timeImageView.snp.right).offset(8)
            make.height.width.greaterThanOrEqualTo(0)
            make.centerY.equalTo(timeImageView)
        }
        
        let lineV = View(hexStr: Constant.SeparatorColorHexStr)
        self.contentView.addSubview(lineV)
        lineV.snp.makeConstraints { make in
            make.top.equalTo(timeImageView.snp.bottom).offset(20)
            make.left.right.equalTo(contentL)
            make.height.equalTo(1)
            make.bottom.equalToSuperview()
        }
    }
    
    func setData(_ model: NotificationModel) {
//        let time = Tool().getInternalBetweenDate(model.created_at,format: "MMM dd yyyy HH:mm:ss")
        self.titleL.text = model.subject
        self.contentL.text = model.summary
        self.timeL.text = model.created_at
        self.redV.isHidden = model.is_read
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
